Skip to content

Do not duplicate -webkit-mask when -webkit-mask-composite sits between - #1574

Open
goranai wants to merge 2 commits into
postcss:mainfrom
goranai:fix/mask-composite-duplicate
Open

goranai wants to merge 2 commits into
postcss:mainfrom
goranai:fix/mask-composite-duplicate

Conversation

@goranai

@goranai goranai commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Fixes the duplicate -webkit-mask and -webkit-mask-composite that Autoprefixer adds when the rule already has -webkit-mask, -webkit-mask-composite, mask in that order (the common gradient border pattern).

Declaration.isAlready() uses prefixes.group(), which stops at -webkit-mask-composite because its unprefixed name differs from mask. MaskComposite now overrides isAlready(). It looks at the neighbouring mask and mask-composite declarations, in both directions, past each other. It stops at the next unprefixed declaration of the same property, as group() does. It also stops at a mask declaration that Autoprefixer already inserted a composite for. That way a later mask-composite still gets its own -webkit-mask-composite. The marker is the property _autoprefixerMaskComposite on the declaration, like _autoprefixerMax and _autoprefixerCascade in lib/declaration.js. It is not printed and does not change the output text.

Behavior change: a rule that already has -webkit-mask or -webkit-mask-composite inside its mask run no longer gets a second copy. This also means a second Autoprefixer run on the same CSS (or on the same PostCSS root) no longer adds more lines. Nothing else in the output changes. I did not touch -webkit-mask-* longhands, uppercase hand-written prefixes, or other properties placed between the mask declarations. Those behave as before.

Tests: two new cases in test/cases/mask-composite.css. Before the fix the supports mask-composite test fails. After the fix node node_modules/uvu/bin.js . '\.test\.js$' gives 289 passed, 0 failed on my machine. oxlint and oxfmt --check are clean on the changed file, and the coverage check (c8, 100% lines) passes locally.

I also ran a random comparison against main on 30000 rules (hand-written prefixed and unprefixed mask declarations, !important, comments, upper case, @media and @supports, six browser queries). When a rule has no hand-written -webkit-mask*, the output is identical to main (0 changed out of all such rules). When it has one, the fix output is the main output with some lines removed, never with lines added or reordered (128 rules). The fix output is stable on a second run for all 30000, main is not for 1206.

Fixes #1573

Validated with Claude Opus 5.5.

Comment thread test/cases/mask-composite.css Outdated
-webkit-mask-composite: xor;
mask: url(full.png);
mask-composite: exclude;
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line to the end of the file please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c29be60, also in mask-composite.out.css.

let vendor = require('../vendor')

class MaskComposite extends Declaration {
/**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not very useful. We need to explain for (let step of [-1, 1]) { and other complex part not explaining things obvious from isAlready

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten in c29be60. The comment now shows the rule that goes wrong (-webkit-mask, -webkit-mask-composite, mask) and why the default check stops early. The loop over [-1, 1] is gone. Each direction is a call to a small groupHas(decl, prefixed, direction) with its own comment, and the stop conditions sit in endsGroup(), each explained.

Comment thread lib/hacks/mask-composite.js Outdated
isAlready(decl, prefixed) {
let nodes = decl.parent.nodes
let index = nodes.indexOf(decl)
for (let step of [-1, 1]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is too complicated, can we make it more readable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split it up in c29be60: isAlready() is one line that checks up and then down, groupHas() walks one direction, and endsGroup() holds the three stop conditions. Behaviour is unchanged. All 289 tests pass, and the mask-composite case still fails on the old code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate -webkit-mask when -webkit-mask, -webkit-mask-composite, mask are already written

2 participants